//
//  UIBarButtonItem+Item.m
//  主流框架的搭建
//
//  Created by 辛路琦 on 16/5/26.
//  Copyright © 2016年 辛路琦. All rights reserved.
//

#import "UIBarButtonItem+Item.h"

@implementation UIBarButtonItem (Item)

+ (UIBarButtonItem *)navBarButtonWithImage:(UIImage *)image hightImage:(UIImage *)hightImage target:(id)target action:(SEL)action
{
    UIButton *button = [[UIButton alloc] init];
    [button setImage:image forState:UIControlStateNormal];
    [button setImage:hightImage forState:UIControlStateHighlighted];
    [button sizeToFit];
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    // 解决item的点击范围过大的问题,记得要设置frame
    UIView *itemView = [[UIView alloc] initWithFrame:button.bounds];
    [itemView addSubview:button];
    return [[UIBarButtonItem alloc] initWithCustomView:itemView];
}

+ (UIBarButtonItem *)navBarButtonWithImage:(UIImage *)image selImage:(UIImage *)hightImage target:(id)target action:(SEL)action
{
    UIButton *button = [[UIButton alloc] init];
    [button setImage:image forState:UIControlStateNormal];
    [button setImage:hightImage forState:UIControlStateSelected];
    [button sizeToFit];
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    // 解决item的点击范围过大的问题,记得要设置frame
    UIView *itemView = [[UIView alloc] initWithFrame:button.bounds];
    [itemView addSubview:button];
    return [[UIBarButtonItem alloc] initWithCustomView:itemView];
}

@end
